<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="之前对 mall-swarm 项目做了升级，注册中心和配置中心都改为使用 Nacos，但是 Jenkins 的自动化部署文档一直都没更新。有些朋友参考原来的文档部署有点小问题，这次对 mall-swarm 的自动化部署文档做个升级，希望对大家有所帮助！  #Jenkins的基本使用使用该部署方案需要对Jenkins有所了解，关于Jenkins的基本使用可以参考：《使用Jenkins一键打包部署S">
<meta property="og:type" content="article">
<meta property="og:title" content="mall-swarm使用Jenkins实现自动化部署">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/ae834480f808.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="之前对 mall-swarm 项目做了升级，注册中心和配置中心都改为使用 Nacos，但是 Jenkins 的自动化部署文档一直都没更新。有些朋友参考原来的文档部署有点小问题，这次对 mall-swarm 的自动化部署文档做个升级，希望对大家有所帮助！  #Jenkins的基本使用使用该部署方案需要对Jenkins有所了解，关于Jenkins的基本使用可以参考：《使用Jenkins一键打包部署S">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:30:19.000Z">
<meta property="article:modified_time" content="2024-02-02T09:15:27.554Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/ae834480f808.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-02 17:15:27'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">mall-swarm使用Jenkins实现自动化部署</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:30:19.000Z" title="发表于 2024-01-21 17:30:19">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-02T09:15:27.554Z" title="更新于 2024-02-02 17:15:27">2024-02-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/%E9%83%A8%E7%BD%B2%E7%AF%87/">部署篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="mall-swarm使用Jenkins实现自动化部署"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>之前对 <code>mall-swarm</code> 项目做了升级，注册中心和配置中心都改为使用 Nacos，但是 Jenkins 的自动化部署文档一直都没更新。有些朋友参考原来的文档部署有点小问题，这次对 <code>mall-swarm</code> 的自动化部署文档做个升级，希望对大家有所帮助！</p>
</blockquote>
<h2 id="Jenkins的基本使用"><a href="#Jenkins的基本使用" class="headerlink" title="#Jenkins的基本使用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#jenkins%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8">#</a>Jenkins的基本使用</h2><p>使用该部署方案需要对Jenkins有所了解，关于Jenkins的基本使用可以参考：<a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/jenkins.html">《使用Jenkins一键打包部署SpringBoot应用，就是这么6！》</a></p>
<h2 id="部署准备"><a href="#部署准备" class="headerlink" title="#部署准备"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#%E9%83%A8%E7%BD%B2%E5%87%86%E5%A4%87">#</a>部署准备</h2><blockquote>
<p>部署之前需要先安装<code>mall-swarm</code>需要的依赖服务，并打包好所有应用的Docker镜像。由于之前已经写过相关教程，这里只提示下关键的步骤，具体可以参考《mall-swarm在Linux环境下的部署（基于Docker容器）》，文档地址：<a target="_blank" rel="noopener" href="http://www.macrozheng.com/#/deploy/mall_swarm_deploy_docker">http://www.macrozheng.com/#/deploy/mall_swarm_deploy_docker</a> 。</p>
</blockquote>
<ul>
<li>需要安装好项目所需的依赖服务，直接使用<code>Docker Compose</code>安装即可，具体服务和版本信息如下；</li>
</ul>
<table>
<thead>
<tr>
<th>组件</th>
<th>版本号</th>
</tr>
</thead>
<tbody><tr>
<td>Mysql</td>
<td>5.7</td>
</tr>
<tr>
<td>Redis</td>
<td>5.0</td>
</tr>
<tr>
<td>MongoDb</td>
<td>4.3.5</td>
</tr>
<tr>
<td>RabbitMq</td>
<td>3.7.15</td>
</tr>
<tr>
<td>Nginx</td>
<td>1.10</td>
</tr>
<tr>
<td>Elasticsearch</td>
<td>7.6.2</td>
</tr>
<tr>
<td>Logstash</td>
<td>7.6.2</td>
</tr>
<tr>
<td>Kibana</td>
<td>7.6.2</td>
</tr>
<tr>
<td>Nacos</td>
<td>1.3.0</td>
</tr>
</tbody></table>
<ul>
<li>打包好所有SpringBoot应用的Docker镜像，具体应用服务信息如下；</li>
</ul>
<table>
<thead>
<tr>
<th>应用</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>mall-monitor</td>
<td>监控中心</td>
</tr>
<tr>
<td>mall-gateway</td>
<td>微服务网关</td>
</tr>
<tr>
<td>mall-auth</td>
<td>认证中心</td>
</tr>
<tr>
<td>mall-admin</td>
<td>商城后台服务</td>
</tr>
<tr>
<td>mall-portal</td>
<td>商城前台服务</td>
</tr>
<tr>
<td>mall-search</td>
<td>商城搜索服务</td>
</tr>
</tbody></table>
<ul>
<li>将应用所有配置添加到Nacos注册中心中去，具体配置文件如下。</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_01-e5c200bc.png"></p>
<h2 id="执行脚本准备"><a href="#执行脚本准备" class="headerlink" title="#执行脚本准备"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#%E6%89%A7%E8%A1%8C%E8%84%9A%E6%9C%AC%E5%87%86%E5%A4%87">#</a>执行脚本准备</h2><blockquote>
<p>Jenkins自动化部署是需要依赖Linux执行脚本的，我们先把需要执行的脚本准备好。</p>
</blockquote>
<ul>
<li>脚本文件都存放在了<code>mall-swarm</code>项目的<code>/document/sh</code>目录下：</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_02-f059d340.png"></p>
<ul>
<li>上传脚本前在IDEA中修改所有脚本文件的换行符格式为<code>LF</code>，否则脚本会无法执行；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_03-d212b31b.png"></p>
<ul>
<li>将所有脚本文件上传到指定目录，这里我们上传到<code>/mydata/sh</code>目录下；</li>
</ul>
<p><img src=""></p>
<ul>
<li>将所有脚本文件都修改为可执行文件:</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod +x ./mall-*</span><br></pre></td></tr></table></figure>

<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_05-05ae8fe3.png"></p>
<h2 id="Jenkins中创建任务"><a href="#Jenkins中创建任务" class="headerlink" title="#Jenkins中创建任务"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#jenkins%E4%B8%AD%E5%88%9B%E5%BB%BA%E4%BB%BB%E5%8A%A1">#</a>Jenkins中创建任务</h2><blockquote>
<p>接下来我们将通过在Jenkins中创建任务来实现自动化部署。由于我们的<code>mall-swarm</code>是个多模块的项目，部署上面和曾经的单模块项目还是有所区别的。</p>
</blockquote>
<h3 id="mall-admin"><a href="#mall-admin" class="headerlink" title="#mall-admin"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#mall-admin">#</a>mall-admin</h3><blockquote>
<p>由于各个模块执行任务的创建都大同小异，下面将详细讲解<code>mall-admin</code>模块任务的创建，其他模块将简略讲解。</p>
</blockquote>
<ul>
<li>首先我们选择<code>构建一个自由风格的软件项目</code>，然后输入任务名称为<code>mall-admin</code>，配置其Git仓库地址，这里我直接使用了Gitee上面的地址：</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_06-bb29e111.png"></p>
<ul>
<li>之后我们创建一个构建，构建<code>mall-swarm</code>项目中的依赖模块，否则当构建可运行的服务模块时会因为无法找到这些模块而构建失败；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 只install mall-common,mall-mbg两个模块</span><br><span class="line">clean install -pl mall-common,mall-mbg -am</span><br></pre></td></tr></table></figure>

<ul>
<li>依赖模块构建示意图：</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_07-24d511ed.png"></p>
<ul>
<li>再创建一个构建，单独构建并打包<code>mall-admin</code>模块：</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_08-362b5409.png"></p>
<ul>
<li>再创建一个构建，通过SSH去执行<code>sh</code>脚本，这里执行的是<code>mall-admin</code>的运行脚本：</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_09-9c1b9f5c.png"></p>
<ul>
<li>点击保存，完成mall-admin的执行任务创建。</li>
</ul>
<h3 id="mall-gateway"><a href="#mall-gateway" class="headerlink" title="#mall-gateway"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#mall-gateway">#</a>mall-gateway</h3><blockquote>
<p><code>mall-gateway</code>和其他模块与<code>mall-admin</code>的创建任务方式基本一致，只需修改构建模块时的<code>pom.xml</code>文件位置和<code>执行脚本</code>位置即可。</p>
</blockquote>
<ul>
<li>我们可以直接从<code>mall-admin</code>模块的任务复制一个过来创建：</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_10-e94b0ef2.png"></p>
<ul>
<li>修改第二个构建中的<code>pom.xml</code>文件位置，改为：<code>$&#123;WORKSPACE&#125;/mall-gateway/pom.xml</code></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_11-69f91cba.png"></p>
<ul>
<li>修改第三个构建中的SSH执行脚本文件位置，改为：<code>/mydata/sh/mall-gateway.sh</code></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_12-bac74573.png"></p>
<ul>
<li>点击保存，完成mall-gateway的执行任务创建。</li>
</ul>
<h3 id="其他模块"><a href="#其他模块" class="headerlink" title="#其他模块"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#%E5%85%B6%E4%BB%96%E6%A8%A1%E5%9D%97">#</a>其他模块</h3><p>其他模块的执行任务创建，参考<code>mall-admin</code>和<code>mall-gateway</code>的创建即可。</p>
<h3 id="任务创建完成"><a href="#任务创建完成" class="headerlink" title="#任务创建完成"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#%E4%BB%BB%E5%8A%A1%E5%88%9B%E5%BB%BA%E5%AE%8C%E6%88%90">#</a>任务创建完成</h3><p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_21-3dcf5d60.png"></p>
<h2 id="Docker网络问题"><a href="#Docker网络问题" class="headerlink" title="#Docker网络问题"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#docker%E7%BD%91%E7%BB%9C%E9%97%AE%E9%A2%98">#</a>Docker网络问题</h2><blockquote>
<p>如果之前使用的是<code>Docker Compose</code>启动所有依赖服务，会默认创建一个网络，所有的依赖服务都会在此网络之中，不同网络内的服务无法互相访问。我这里创建的网络是<code>deploy_default</code>，所以需要指定<code>sh</code>脚本中服务运行的的网络，否则启动的应用服务会无法连接到依赖服务。</p>
</blockquote>
<ul>
<li>可以使用<code>docker inspect mysql</code>命令来查看mysql服务所在的网络；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_19-028c4e49.png"></p>
<ul>
<li>也可以通过<code>docker network ls</code>来查看所有网络；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@local-linux ~]# docker network ls</span><br><span class="line">NETWORK ID          NAME                     DRIVER              SCOPE</span><br><span class="line">59b309a5c12f        bridge                   bridge              local</span><br><span class="line">3a6f76a8920d        deploy_default           bridge              local</span><br><span class="line">ef34fe69992b        host                     host                local</span><br><span class="line">a65be030c632        none     </span><br></pre></td></tr></table></figure>

<ul>
<li>修改所有<code>sh</code>脚本，修改服务运行的网络，添加一行<code>--network deploy_default \</code>即可。</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_20-64968d13.png"></p>
<h2 id="模块启动顺序问题"><a href="#模块启动顺序问题" class="headerlink" title="#模块启动顺序问题"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#%E6%A8%A1%E5%9D%97%E5%90%AF%E5%8A%A8%E9%A1%BA%E5%BA%8F%E9%97%AE%E9%A2%98">#</a>模块启动顺序问题</h2><blockquote>
<p>由于作为注册中心和配置中心的Nacos已经启动了，其他模块基本没有启动顺序的限制，但是最好还是按照下面的顺序启动。</p>
</blockquote>
<p>推荐启动顺序：</p>
<ul>
<li>mall-auth</li>
<li>mall-gateway</li>
<li>mall-monitor</li>
<li>mall-admin</li>
<li>mall-portal</li>
<li>mall-search</li>
</ul>
<h2 id="运行完成效果展示"><a href="#运行完成效果展示" class="headerlink" title="#运行完成效果展示"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#%E8%BF%90%E8%A1%8C%E5%AE%8C%E6%88%90%E6%95%88%E6%9E%9C%E5%B1%95%E7%A4%BA">#</a>运行完成效果展示</h2><ul>
<li>查看API文档信息，访问地址：<a target="_blank" rel="noopener" href="http://192.168.3.101:8201/doc.html">http://192.168.3.101:8201/doc.html</a></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_13-fed37937.png"></p>
<ul>
<li>查看注册中心注册服务信息，访问地址：<a target="_blank" rel="noopener" href="http://192.168.3.101:8848/nacos/">http://192.168.3.101:8848/nacos/</a></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_14-d9888132.png"></p>
<ul>
<li>监控中心应用信息，访问地址：<a target="_blank" rel="noopener" href="http://192.168.3.101:8101/">http://192.168.3.101:8101</a></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_15-ec4b9178.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_16-4da79bd3.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_17-0b991594.png"></p>
<ul>
<li>日志收集系统信息，访问地址：<a target="_blank" rel="noopener" href="http://192.168.3.101:5601/">http://192.168.3.101:5601</a></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/mall_swarm_jks_18-9e0da61c.png"></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="#总结"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_jenkins.html#%E6%80%BB%E7%BB%93">#</a>总结</h2><p>我们通过在Jenkins中创建任务，完成了<code>mall-swarm</code>项目的自动化部署工作，这样当我们每次修改完代码后，只需点击启动任务，就可以实现一键打包部署，省去了频繁打包部署的麻烦。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/ae834480f808.html">https://ko25891wan.gitlab.io/2024/01/ae834480f808.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/98cfc2cb76b4.html" title="mall-swarm微服务项目在K8S下的最佳实践"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">mall-swarm微服务项目在K8S下的最佳实践</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/27851c2fc81c.html" title="SpringBoot应用整合ELK实现日志收集"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">SpringBoot应用整合ELK实现日志收集</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Jenkins%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8"><span class="toc-number">1.</span> <span class="toc-text">Jenkins的基本使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%83%A8%E7%BD%B2%E5%87%86%E5%A4%87"><span class="toc-number">2.</span> <span class="toc-text">部署准备</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%89%A7%E8%A1%8C%E8%84%9A%E6%9C%AC%E5%87%86%E5%A4%87"><span class="toc-number">3.</span> <span class="toc-text">执行脚本准备</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Jenkins%E4%B8%AD%E5%88%9B%E5%BB%BA%E4%BB%BB%E5%8A%A1"><span class="toc-number">4.</span> <span class="toc-text">Jenkins中创建任务</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#mall-admin"><span class="toc-number">4.1.</span> <span class="toc-text">mall-admin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#mall-gateway"><span class="toc-number">4.2.</span> <span class="toc-text">mall-gateway</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E6%A8%A1%E5%9D%97"><span class="toc-number">4.3.</span> <span class="toc-text">其他模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%BB%E5%8A%A1%E5%88%9B%E5%BB%BA%E5%AE%8C%E6%88%90"><span class="toc-number">4.4.</span> <span class="toc-text">任务创建完成</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker%E7%BD%91%E7%BB%9C%E9%97%AE%E9%A2%98"><span class="toc-number">5.</span> <span class="toc-text">Docker网络问题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A8%A1%E5%9D%97%E5%90%AF%E5%8A%A8%E9%A1%BA%E5%BA%8F%E9%97%AE%E9%A2%98"><span class="toc-number">6.</span> <span class="toc-text">模块启动顺序问题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C%E5%AE%8C%E6%88%90%E6%95%88%E6%9E%9C%E5%B1%95%E7%A4%BA"><span class="toc-number">7.</span> <span class="toc-text">运行完成效果展示</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">8.</span> <span class="toc-text">总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>